home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / os2 / ue311gcc.zip / IBMPC.C < prev    next >
C/C++ Source or Header  |  1993-01-01  |  18KB  |  787 lines

  1. /*
  2.  * The routines in this file provide support for the IBM-PC and other
  3.  * compatible terminals. It goes directly to the graphics RAM to do
  4.  * screen output. It compiles into nothing if not an IBM-PC driver
  5.  * Supported monitor cards include CGA, MONO and EGA.
  6.  */
  7.  
  8. #define    termdef    1            /* don't define "term" external */
  9.  
  10. #include        <stdio.h>
  11. #include    <dos.h>
  12. #include    "estruct.h"
  13. #include    "eproto.h"
  14. #include        "edef.h"
  15. #include    "elang.h"
  16. #if    GCC
  17. #include    <pc.h>
  18. #define    inp(x)        inportb ((x))
  19. #define    outp(x, y)    outportb ((x), (y))
  20. #endif
  21.  
  22. #if     IBMPC
  23. #define NROW    50            /* Max Screen size.        */
  24. #define NCOL    80                      /* Edit if you want to.         */
  25. #define    MARGIN    8            /* size of minimim margin and    */
  26. #define    SCRSIZ    64            /* scroll size for extended lines */
  27. #define    NPAUSE    200            /* # times thru update to pause */
  28. #define BEL     0x07                    /* BEL character.               */
  29. #define ESC     0x1B                    /* ESC character.               */
  30. #define    SPACE    32            /* space character        */
  31.  
  32. #define    SCADC    0xb8000000L        /* CGA address of screen RAM    */
  33. #define    SCADM    0xb0000000L        /* MONO address of screen RAM    */
  34. #define SCADE    0xb8000000L        /* EGA/VGA address of screen RAM*/
  35.  
  36. #define MONOCRSR 0x0B0D            /* monochrome cursor        */
  37. #define CGACRSR 0x0607            /* CGA cursor            */
  38. #define EGACRSR 0x0709            /* EGA/VGA cursor        */
  39.  
  40. #define    CDCGA    0            /* color graphics card        */
  41. #define    CDMONO    1            /* monochrome text card        */
  42. #define    CDEGA    2            /* EGA color adapter        */
  43. #define    CDVGA    3            /* VGA color adapter        */
  44. #define    CDVGA12    4            /* VGA 12 line mode        */
  45. #define    CDCGA40    5            /* CGA 40 wide mode        */
  46. #define    CDSENSE    9            /* detect the card type        */
  47.  
  48. #define NDRIVE    6            /* number of screen drivers    */
  49.  
  50. typedef struct sdrive {
  51.     char drv_name[8];        /* screen driver name    */
  52.     long drv_scradd;        /* address of segment of screen ram */
  53.     int drv_rows;            /* # of rows for screen driver */
  54.     int drv_cols;            /* # of columns for screen driver */
  55. } SDRIVE;
  56.  
  57. SDRIVE scr_drive[] = {
  58.     "CGA",   SCADC, 25, 80,        /* standard color card        */
  59.     "MONO",  SCADM, 25, 80,        /* momochrome graphics adapter    */
  60.     "EGA",   SCADE, 43, 80,        /* Enhanced graphics adapter    */
  61.     "VGA",   SCADE, 50, 80,        /* Very Enhanced graphics adapter*/
  62.     "VGA12", SCADE, 12, 80,        /* 12 lines x 80 cols        */
  63.     "CGA40", SCADC, 25, 40,        /* low resolution CGA        */
  64. };
  65.  
  66. int dtype = -1;                /* current display type        */
  67.  
  68. long scadd;                /* address of screen ram    */
  69. #if    GCC
  70. short *scptr[NROW];            /* pointer to screen lines    */
  71. #else
  72. int *scptr[NROW];            /* pointer to screen lines    */
  73. #endif
  74. unsigned int sline[NCOL];        /* screen line image        */
  75. int num_cols;                /* current number of columns    */
  76. int orig_mode;                /* screen mode on entry        */
  77. int egaexist = FALSE;            /* is an EGA card available?    */
  78. int vgaexist = FALSE;            /* is video graphics array available? */
  79. extern union REGS rg;            /* cpu register for use of DOS calls */
  80. int revflag = FALSE;            /* are we currently in rev video? */
  81. int desk_rows;                /* number of rows on current desktop */
  82. int desk_cols;                /* number of cols on current desktop */
  83.  
  84.  
  85. ibmmove();
  86. ibmeeol();
  87. ibmputc();
  88. ibmeeop();
  89. ibmclrdesk();
  90. ibmrev();
  91. ibmcres();
  92. spal();
  93. ibmbeep();
  94. ibmopen();
  95. ibmclose();
  96. ibmkopen();
  97. ibmkclose();
  98. scinit();
  99. screen_init();
  100. int getboard();
  101. egaopen();
  102. egaclose();
  103. cga40_open();
  104. cga40_close();
  105. change_width();
  106. fnclabel();
  107.  
  108. #if    COLOR
  109. ibmfcol();
  110. ibmbcol();
  111. int    cfcolor = -1;        /* current forground color */
  112. int    cbcolor = -1;        /* current background color */
  113. int    ctrans[] =        /* ansi to ibm color translation table */
  114.     {0, 4, 2, 6, 1, 5, 3, 7,
  115.      8, 12, 10, 14, 9, 13, 11, 15};
  116. #endif
  117.  
  118. /*
  119.  * Standard terminal interface dispatch table. Most of the fields point into
  120.  * "termio" code.
  121.  */
  122. TERM    term    = {
  123.     NROW-1,
  124.         NROW-1,
  125.         NCOL,
  126.         NCOL,
  127.     0, 0,
  128.     MARGIN,
  129.     SCRSIZ,
  130.     NPAUSE,
  131.         ibmopen,
  132.         ibmclose,
  133.     ibmkopen,
  134.     ibmkclose,
  135.         ttgetc,
  136.     ibmputc,
  137.         ttflush,
  138.         ibmmove,
  139.         ibmeeol,
  140.         ibmeeop,
  141.         ibmclrdesk,
  142.         ibmbeep,
  143.     ibmrev,
  144.     ibmcres
  145. #if    COLOR
  146.     , ibmfcol,
  147.     ibmbcol
  148. #endif
  149. };
  150.  
  151. #if    COLOR
  152. ibmfcol(color)    /* set the current output color */
  153.  
  154. int color;    /* color to set */
  155.  
  156. {
  157.     cfcolor = ctrans[color];
  158. }
  159.  
  160. ibmbcol(color)    /* set the current background color */
  161.  
  162. int color;    /* color to set */
  163.  
  164. {
  165.         cbcolor = ctrans[color];
  166. }
  167. #endif
  168.  
  169. ibmmove(row, col)
  170. {
  171.     rg.h.ah = 2;        /* set cursor position function code */
  172.     rg.h.dl = col + term.t_colorg;
  173.     rg.h.dh = row + term.t_roworg;
  174.     rg.h.bh = 0;        /* set screen page number */
  175.     int86(0x10, &rg, &rg);
  176. }
  177.  
  178. ibmeeol()    /* erase to the end of the line */
  179.  
  180. {
  181.     unsigned int attr;    /* attribute byte mask to place in RAM */
  182. #if    GCC
  183.     unsigned short *lnptr;    /* pointer to the destination line */
  184. #else
  185.     unsigned int *lnptr;    /* pointer to the destination line */
  186. #endif
  187.     int i;
  188.     int ccol;    /* current column cursor lives */
  189.     int crow;    /*       row    */
  190.  
  191.     /* find the current cursor position */
  192.  
  193. #if    0
  194.     ScreenGetCursor (&crow, &ccol);
  195. #else
  196.     rg.h.ah = 3;        /* read cursor position function code */
  197.     rg.h.bh = 0;        /* current video page */
  198.     int86(0x10, &rg, &rg);
  199.     ccol = rg.h.dl - term.t_colorg;    /* record current column */
  200.     crow = rg.h.dh - term.t_roworg;    /* and row */
  201. #endif
  202.  
  203.     /* build the attribute byte and setup the screen pointer */
  204. #if    COLOR
  205.     if (dtype != CDMONO)
  206.         if (revflag)
  207.             attr = (((cfcolor & 15) << 4) | (cbcolor & 15)) << 8;
  208.         else
  209.             attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  210.     else
  211.         if (revflag)
  212.             attr = 0x7000;
  213.         else
  214.             attr = 0x0700;
  215. #else
  216.     attr = 0x0700;
  217. #endif
  218.     lnptr = &sline[0];
  219.     for (i=0; i < term.t_ncol; i++)
  220.         *lnptr++ = SPACE | attr;
  221.  
  222.     if (flickcode && (dtype == CDCGA || dtype == CDCGA40)) {
  223.         /* wait for vertical retrace to be off */
  224.         while ((inp(0x3da) & 8))
  225.             ;
  226.     
  227.         /* and to be back on */
  228.         while ((inp(0x3da) & 8) == 0)
  229.             ;
  230.     }            
  231.  
  232.     /* and send the string out */
  233.  
  234. #if    0
  235.     movmem(&sline[0], scptr[crow]+ccol, (term.t_ncol-ccol)*2);
  236. #else
  237.     movmem(&sline[0], scptr[crow+term.t_roworg]+ccol+term.t_colorg, (term.t_ncol-ccol)*2);
  238. #endif
  239.  
  240. }
  241.  
  242. ibmputc(ch) /* put a character at the current position in the
  243.            current colors */
  244.  
  245. int ch;
  246.  
  247. {
  248.     /* if its a newline, we have to move the cursor */
  249.     if (ch == '\n' || ch == '\r') {
  250.         rg.h.ah = 3;
  251.         int86(0x10, &rg, &rg);
  252.         if (rg.h.dh == 24) {
  253.             ibmmove(20, 0);
  254.             /* we must scroll the screen */
  255.             rg.h.ah = 6;    /* scroll up */
  256.             rg.h.al = 1;    /* # of lines to scroll by */
  257. #if    COLOR
  258.             rg.h.bh = cfcolor; /* attribute for blank line */
  259. #else
  260.             rg.h.bh = 0; /* attribute for blank line */
  261. #endif
  262.             rg.x.cx = 0;    /* upper left corner of scroll */
  263.             rg.x.dx = 0x184f;/* lower right */
  264.             int86(0x10, &rg, &rg);
  265.             rg.h.dh = 23;
  266.         }
  267.         ibmmove(rg.h.dh + 1, 0);
  268.         return;
  269.     }
  270.  
  271. #if    1
  272.     if (ch == '\b') {
  273.         /* backup the cursor by 1 position */
  274.         rg.h.ah = 3;        /* read current position */
  275.         int86(0x10, &rg, &rg);
  276.         rg.h.dl--;        /* move it forward one */
  277.         rg.h.ah = 2;        /* set its new position */
  278.         int86(0x10, &rg, &rg);
  279.     
  280.         rg.h.ah = 9;        /* write char with attributes to cursor position */
  281.         rg.h.bh = 0;        /* display page zero */
  282.         rg.x.cx = 1;        /* only one please! */
  283.         rg.h.al = ' ';        /* character to write */
  284.         rg.h.bl = ((ctrans[gbcolor] << 4) | ctrans[gfcolor]);/* attribute */
  285.         int86(0x10, &rg, &rg);
  286.         return;
  287.     }
  288.  
  289.     if (ch == 7) {
  290.         TTbeep();
  291.         return;
  292.     }
  293.  
  294.     rg.h.ah = 9;        /* write char with attributes to cursor position */
  295.     rg.h.bh = 0;        /* display page zero */
  296.     rg.x.cx = 1;        /* only one please! */
  297.     rg.h.al = ch;        /* character to write */
  298.     rg.h.bl = ((ctrans[gbcolor] << 4) | ctrans[gfcolor]);    /* attribute */
  299.     int86(0x10, &rg, &rg);
  300.  
  301.     /* advance the cursor by 1 position */
  302.     rg.h.ah = 3;        /* read current position */
  303.     int86(0x10, &rg, &rg);
  304.     rg.h.dl++;        /* move it forward one */
  305.     rg.h.ah = 2;        /* set its new position */
  306.     int86(0x10, &rg, &rg);
  307. #else
  308.     rg.h.ah = 14;        /* write char to screen with current attrs */
  309.     rg.h.al = ch;
  310. #if    COLOR
  311.     if (dtype != CDMONO)
  312.         rg.h.bl = cfcolor;
  313.     else
  314.         rg.h.bl = 0x07;
  315. #else
  316.     rg.h.bl = 0x07;
  317. #endif
  318.     int86(0x10, &rg, &rg);
  319. #endif
  320. }
  321.  
  322. ibmeeop()
  323.  
  324. {
  325.     rg.h.ah = 6;        /* scroll page up function code */
  326.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  327.     rg.x.cx = (term.t_roworg << 8) | (term.t_colorg);
  328.                 /* upper left corner of scroll */
  329.     rg.x.dx = ((term.t_nrow + term.t_roworg) << 8) |
  330.             (term.t_ncol + term.t_colorg - 1);
  331.                 /* lower right corner of scroll */
  332. #if    COLOR
  333.     if (dtype != CDMONO)
  334.         if (revflag)
  335.             rg.h.bh = ((ctrans[gfcolor] & 15) << 4) | (ctrans[gbcolor] & 15);
  336.         else
  337.             rg.h.bh = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  338.     else
  339.         if (revflag)
  340.             rg.h.bh = 70;
  341.         else
  342.             rg.h.bh = 07;
  343. #else
  344.     rg.h.bh = 07;
  345. #endif
  346.     int86(0x10, &rg, &rg);
  347. }
  348.  
  349. ibmclrdesk()
  350.  
  351. {
  352.     int attr;        /* attribute to fill screen with */
  353.  
  354.     rg.h.ah = 6;        /* scroll page up function code */
  355.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  356.     rg.x.cx = 0;        /* upper left corner of scroll */
  357.     rg.x.dx = (desk_rows << 8) | desk_cols;
  358.                 /* lower right corner of scroll */
  359. #if    COLOR
  360.     if (dtype != CDMONO)
  361.         if (revflag)
  362.             attr = ((ctrans[gfcolor] & 15) << 4) | (ctrans[deskcolor] & 15);
  363.         else
  364.             attr = ((ctrans[deskcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  365.     else
  366.         if (revflag)
  367.             attr = 70;
  368.         else
  369.             attr = 07;
  370. #else
  371.     attr = 07;
  372. #endif
  373.     rg.h.bh = attr;
  374.     int86(0x10, &rg, &rg);
  375. }
  376.  
  377. ibmrev(state)    /* change reverse video state */
  378.  
  379. int state;    /* TRUE = reverse, FALSE = normal */
  380.  
  381. {
  382.     revflag = state;
  383. }
  384.  
  385. extern dumpscreens();
  386.  
  387. ibmcres(res) /* change screen resolution */
  388.  
  389. char *res;    /* resolution to change to */
  390.  
  391. {
  392.     int i;        /* index */
  393.  
  394.     for (i = 0; i < NDRIVE; i++)
  395.         if (strcmp(res, scr_drive[i].drv_name) == 0) {
  396.             scinit(i);
  397.             return(TRUE);
  398.         }
  399.     return(FALSE);
  400. }
  401.  
  402. spal(mode)    /* reset the pallette registers */
  403.  
  404. char *mode;
  405.  
  406. {
  407.     /* nothin here now..... */
  408. }
  409.  
  410. ibmbeep()
  411. {
  412. #if    MWC
  413.     ttputc(BEL);
  414. #else
  415.     bdos(6, BEL, 0);
  416. #endif
  417. }
  418.  
  419. ibmopen()
  420. {
  421.     scinit(CDSENSE);
  422.     revexist = TRUE;
  423.     revflag = FALSE;
  424.         ttopen();
  425. }
  426.  
  427. ibmclose()
  428.  
  429. {
  430. #if    COLOR
  431.     ibmfcol(7);
  432.     ibmbcol(0);
  433. #endif
  434.  
  435.     /* exit in the same mode that we entered */
  436.     if (dtype != orig_mode) {
  437.         scinit(orig_mode);
  438.         movecursor(term.t_nrow, 0);
  439.         TTflush();
  440.     }
  441.     dtype = -1;
  442.     ttclose();
  443. }
  444.  
  445. ibmkopen()    /* open the keyboard */
  446.  
  447. {
  448. }
  449.  
  450. ibmkclose() /* close the keyboard */
  451.  
  452. {
  453. }
  454.  
  455. scinit(type) /* initialize the screen head pointers */
  456.  
  457. int type;    /* type of adapter to init for */
  458.  
  459. {
  460.     /* if asked...find out what display is connected */
  461.     if (type == CDSENSE)
  462.         type = getboard();
  463.  
  464.     /* if we have nothing to do....don't do it */
  465.     if (dtype == type)
  466.         return(TRUE);
  467.  
  468.     /* if we try to switch to EGA and there is none, don't */
  469.     if (type == CDEGA && !egaexist)
  470.         return(FALSE);
  471.  
  472.     /* if we try to switch to VGA and there is none, don't */
  473.     if (type == CDVGA && !vgaexist )
  474.         return(FALSE);
  475.  
  476.     /* if we had the EGA or VGA open... close it */
  477.     if (dtype == CDEGA || dtype == CDVGA || dtype == CDVGA12)
  478.         egaclose();
  479.  
  480.     /* if we had the CGA40 open... close it */
  481.     if (dtype == CDCGA40)
  482.         cga40_close();
  483.  
  484.     /* and set up the various parameters as needed */
  485.     scadd = scr_drive[type].drv_scradd;
  486.     switch (type) {
  487.         case CDMONO:    /* Monochrome adapter */
  488.         case CDCGA:    /* Color graphics adapter */
  489.                 break;
  490.  
  491.         case CDCGA40:    /* Color graphics adapter */
  492.                 cga40_open();
  493.                 break;
  494.  
  495.         case CDEGA:    /* Enhanced graphics adapter */
  496.                 egaopen(CDEGA);
  497.                 break;
  498.  
  499.         case CDVGA:    /* video graphics array - acts as EGA but more lines */
  500.                 egaopen(CDVGA);
  501.                 break;
  502.  
  503.         case CDVGA12:    /* Video Graphics Array 12 line mode */
  504.                 egaopen(CDVGA12);
  505.                 break;
  506.  
  507.     }
  508.     maxlines(scr_drive[type].drv_rows);
  509.  
  510.     /* reset the $sres environment variable */
  511.     strcpy(sres, scr_drive[type].drv_name);
  512.  
  513.     /* resize any screens that need it! */
  514.     screen_init(dtype, type);
  515.     dtype = type;
  516.  
  517.     return(TRUE);
  518. }
  519.  
  520. screen_init(dtype, type) /* initialize the screen head pointers */
  521.  
  522. int dtype;    /* original screen type (-1 if first time!) */
  523. int type;    /* new type of adapter to adjust screens for */
  524.  
  525. {
  526.     int full_screen;    /* is the active screen full size */
  527.  
  528.     /* is the front screen full size? */
  529.     if ((dtype != -1) &&
  530.        (scr_drive[dtype].drv_rows == (term.t_nrow + 1)) &&
  531.         (scr_drive[dtype].drv_cols == term.t_ncol))
  532.         full_screen = TRUE;
  533.     else
  534.         full_screen = FALSE;
  535.  
  536.     /* set up the new desktop size */
  537.     desk_rows = scr_drive[type].drv_rows;
  538.     desk_cols = scr_drive[type].drv_cols;
  539.  
  540.     /* recalculate the screen line pointer array */
  541.     change_width(desk_cols);
  542.  
  543.     /* first time, or if we are full screen */
  544.     if ((dtype == -1) || full_screen) {
  545.         newsize(TRUE, desk_rows);
  546.         newwidth(TRUE, desk_cols);
  547.     }
  548.  
  549. #if    WINDOW_TEXT
  550.     refresh_screen(first_screen);
  551. #endif
  552.     return(TRUE);
  553. }
  554.  
  555. int change_width(ncols)
  556.  
  557. int ncols;    /* number of columns across */
  558.  
  559. {
  560.     union {
  561. #if    GCC
  562.         unsigned long laddr;    /* long form of address */
  563. #else
  564.         long laddr;    /* long form of address */
  565. #endif
  566.         int *paddr;    /* pointer form of address */
  567.     } addr;
  568.     int i;
  569.  
  570.     /* re-initialize the screen pointer array */
  571.     for (i = 0; i < NROW; i++) {
  572.         addr.laddr = scadd + (long)(ncols * i * 2);
  573. #if    GCC
  574.         scptr[i] = 0xe0000000L +
  575.                    (((addr.laddr & 0xffff0000L) >> 12) +
  576.                     (addr.laddr & 0x0000ffffL));
  577. #else
  578.         scptr[i] = addr.paddr;
  579. #endif
  580.     }
  581. }
  582.  
  583. /* getboard:    Determine which type of display board is attached.
  584.         Current known types include:
  585.  
  586.         CDMONO    Monochrome graphics adapter
  587.         CDCGA    Color Graphics Adapter
  588.         CDEGA    Extended graphics Adapter
  589.         CDVGA    Vidio Graphics Array
  590.  
  591.         if MONO    set to MONO
  592.            CGA40 set to CGA40    test as appropriate
  593.            CGA    set to CGA    EGAexist = FALSE VGAexist = FALSE
  594.            EGA    set to CGA    EGAexist = TRUE  VGAexist = FALSE
  595.            VGA    set to CGA    EGAexist = TRUE  VGAexist = TRUE
  596. */
  597.  
  598. int getboard()
  599.  
  600. {
  601.     int type;    /* board type to return */
  602.  
  603.     type = CDCGA;
  604.     int86(0x11, &rg, &rg);
  605.     if ((((rg.x.ax >> 4) & 3) == 3))
  606.         type = CDMONO;
  607.  
  608.     /* test for 40 col mode */
  609.     rg.h.ah = 15;
  610.     int86(0x10, &rg, &rg);
  611.     if (rg.h.al == 1)
  612.         type = CDCGA40;
  613.  
  614.     /* save the original video mode */
  615.     orig_mode = type;
  616.  
  617.     /* test if EGA present */
  618.     rg.x.ax = 0x1200;
  619.     rg.x.bx = 0xff10;
  620.     int86(0x10,&rg, &rg);        /* If EGA, bh=0-1 and bl=0-3 */
  621.     egaexist = !(rg.x.bx & 0xfefc);    /* Yes, it's EGA */
  622.     if (egaexist) {
  623.         /* Adapter says it's an EGA. We'll get the same response
  624.            from a VGA, so try to tell the two apart */
  625.         rg.x.ax = 0x1a00;    /* read display combination */
  626.         int86(0x10,&rg,&rg);
  627.         if (rg.h.al == 0x1a && (rg.h.bl == 7 || rg.h.bl == 8)) {
  628.             /* Function is supported and it's a PS/2 50,60,80 with
  629.                analog display, so it's VGA (I hope!) */
  630.             vgaexist = TRUE;
  631.         } else {
  632.             /* Either BIOS function not supported or something
  633.                other then VGA so set it to be EGA */
  634.             vgaexist = FALSE;
  635.         }
  636.     }
  637.     return(type);
  638. }
  639.  
  640. egaopen(mode) /* init the computer to work with the EGA or VGA */
  641.  
  642. int mode;    /* mode to select [CDEGA/CDVGA] */
  643.  
  644. {
  645.     /* set the proper number of scan lines */
  646.     rg.h.ah = 18;
  647.     switch (mode) {
  648.  
  649.         case CDEGA:    rg.h.al = 1;
  650.                 break;
  651.  
  652.         case CDVGA:    rg.h.al = 2;
  653.                 break;
  654.  
  655.         case CDVGA12:    rg.h.al = 0;
  656.                 break;
  657.  
  658.     }
  659.     rg.h.bl = 48;
  660.     int86(16, &rg, &rg);
  661.  
  662.     /* put the beast into EGA 43/VGA 50/VGA 12 line mode */
  663.     rg.x.ax = 3;
  664.     int86(16, &rg, &rg);
  665.  
  666.     /* set the proper character set */
  667.     if (mode == CDVGA12) {
  668.         rg.h.al = 20;    /*  to 8 by 16 double dot ROM         */
  669.     } else {
  670.         rg.h.al = 18;    /*  to 8 by 8 double dot ROM         */
  671.     }
  672.     rg.h.ah = 17;        /* set char. generator function code */
  673.     rg.h.bl = 0;        /* block 0                           */
  674.     int86(16, &rg, &rg);
  675.  
  676.     /* select the alternative Print Screen function */
  677.     rg.h.ah = 18;        /* alternate select function code    */
  678.     rg.h.al = 0;        /* clear AL for no good reason       */
  679.     rg.h.bl = 32;        /* alt. print screen routine         */
  680.     int86(16, &rg, &rg);
  681.  
  682.     /* resize the cursor */
  683.     rg.h.ah = 1;        /* set cursor size function code */
  684.     rg.x.cx = 0x0607;    /* turn cursor on code */
  685.     int86(0x10, &rg, &rg);
  686.  
  687.     /* video bios bug patch */
  688.     outp(0x3d4, 10);
  689.     outp(0x3d5, 6);
  690. }
  691.  
  692. egaclose()
  693.  
  694. {
  695.     /* set the proper number of scan lines for CGA */
  696.     rg.h.ah = 18;
  697.     rg.h.al = 2;
  698.     rg.h.bl = 48;
  699.     int86(16, &rg, &rg);
  700.  
  701.     /* put the beast into 80 column mode */
  702.     rg.x.ax = 3;
  703.     int86(16, &rg, &rg);
  704. }
  705.  
  706. cga40_open()
  707.  
  708. {
  709.     /* put the beast into 40 column mode */
  710.     rg.x.ax = 1;
  711.     int86(16, &rg, &rg);
  712. }
  713.  
  714. cga40_close()
  715.  
  716. {
  717.     /* put the beast into 80 column mode */
  718.     rg.x.ax = 3;
  719.     int86(16, &rg, &rg);
  720. }
  721.  
  722. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  723.  
  724. int row;    /* row of screen to place outstr on */
  725. char *outstr;    /* string to write out (must be term.t_ncol long) */
  726. int forg;    /* forground color of string to write */
  727. int bacg;    /* background color */
  728.  
  729. {
  730.     unsigned int attr;    /* attribute byte mask to place in RAM */
  731. #if    GCC
  732.     unsigned short *lnptr;    /* pointer to the destination line */
  733. #else
  734.     unsigned int *lnptr;    /* pointer to the destination line */
  735. #endif
  736.     int i;
  737.  
  738.     /* build the attribute byte and setup the screen pointer */
  739. #if    COLOR
  740.     if (dtype != CDMONO)
  741.         if (revflag)
  742.             attr = (ctrans[forg] << 12) | (ctrans[bacg] << 8);
  743.         else
  744.             attr = (ctrans[bacg] << 12) | (ctrans[forg] << 8);
  745.     else
  746.         if ((bacg || revflag) && !(bacg && revflag))
  747.             attr = 0x7000;
  748.         else
  749.             attr = 0x0700;
  750. #else
  751.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  752. #endif
  753.     lnptr = &sline[0];
  754.     for (i=0; i<term.t_ncol; i++)
  755.         *lnptr++ = (outstr[i] & 255) | attr;
  756.  
  757.     if (flickcode && (dtype == CDCGA)) {
  758.         /* wait for vertical retrace to be off */
  759.         while ((inp(0x3da) & 8))
  760.             ;
  761.     
  762.         /* and to be back on */
  763.         while ((inp(0x3da) & 8) == 0)
  764.             ;
  765.     }
  766.  
  767.     /* and send the string out */
  768.     movmem(&sline[0], scptr[row+term.t_roworg]+term.t_colorg,term.t_ncol*2);
  769. }
  770.  
  771. #if    FLABEL
  772. fnclabel(f, n)    /* label a function key */
  773.  
  774. int f,n;    /* default flag, numeric argument [unused] */
  775.  
  776. {
  777.     /* on machines with no function keys...don't bother */
  778.     return(TRUE);
  779. }
  780. #endif
  781. #else
  782. ibmhello()
  783. {
  784. }
  785. #endif
  786.  
  787.